package com.qth.valet.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qth.valet.common.theadlocal.UserOrDriverIdHolder;
import com.qth.valet.common.utils.ResponseResult;
import com.qth.valet.entity.po.DriverBalanceDetail;
import com.qth.valet.service.DriverBalanceDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 蔡徐坤
 * @since 2025-09-15
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/qth/driver_balance_detail")
public class DriverBalanceDetailController {

    private final DriverBalanceDetailService driverBalanceDetailService;

    /**
     * 司机查询余额明细分页
     */
    @GetMapping("/page")
    public ResponseResult<IPage<DriverBalanceDetail>> page(@RequestParam(defaultValue = "1") long pageNum,
                                                           @RequestParam(defaultValue = "10") long pageSize) {
        Page<DriverBalanceDetail> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<DriverBalanceDetail> qw = new LambdaQueryWrapper<DriverBalanceDetail>()
                .eq(DriverBalanceDetail::getDriverId, UserOrDriverIdHolder.getDriverId())
                .orderByDesc(DriverBalanceDetail::getId);
        Page<DriverBalanceDetail> res = driverBalanceDetailService.page(page, qw);
        return ResponseResult.success(res);
    }

}
